# -*- coding: utf-8 -*-
from afpy.ldap.node import User as BaseUser
from afpy.ldap.node import GroupOfNames
from afpy.ldap import schema

class User(BaseUser):
    _rdn = 'uid'
    _base_dn = 'ou=People,dc=crane,dc=hust,dc=edu'

    # default user properties
    _defaults = dict(
        objectClass = ['top', 'posixAccount', 'inetOrgPerson', 'organizationalPerson', 'shadowAccount', 'person'],
        st='CN',
       )
    cn = schema.StringProperty('cn', title='cn', required=True)
    uid = schema.StringProperty('uid', title='Login',  required=True)
    gid = schema.IntegerProperty('gid', title='Group', required=True)
    sn = schema.UnicodeProperty('sn', title='Surname')
    mail = schema.StringProperty('mail',title='Email')



#class BaseGroup(Node):
#    """base class for group nodes"""
#    _rdn = 'cn'
#    _memberAttr = 'memberUid'
#    _defaults = {'objectClass': ['posixGroup', 'top']}#
#
#    member = schema.SetProperty('memberUid', title='Members')
#    member_nodes = schema.SetOfNodesProperty('memberUid', title='Members', node_class=User)

#    def __repr__(self):
#        return '<%s at %s (%s members)>' % (self.__class__.__name__,
#                                    self.dn, len(self.member))
#    def pprint(self):
#        out = []
#        out.append(self.cn)
#        out.append('-'*len(self.cn))
#        users = self.member_nodes
#        for u in users:
#            out.append(getattr(u, u.rdn))
#        return '\n'.join(out)

class Role(GroupOfNames):
    _rdn = 'cn'
    _base_dn = 'ou=Role,dc=crane,dc=hust,dc=edu'

    cn = schema.StringProperty('cn', title='cn', required=True)
